layui.use(['upload','element','table','form','laytpl'],function(){
			 var $ = layui.jquery
  		,upload = layui.upload
			,table = layui.table
			,layer = layui.layer
			,element =layui.element
			,form = layui.form
			,laytpl = layui.laytpl
			//取sessionStorage里面的userKey
			var teacherInfo = document.getElementById("teacherInfo").innerHTML;
			
			var userKey = JSON.parse(sessionStorage.getItem("userKey"));
			console.log(userKey)
			if(userKey) {
				//如果存在,则说明登录过,先比对过期时间
				var delayTime = userKey.delayTime
				var nowTime = new Date().getTime()
				if(nowTime < delayTime) {
					//登录未失效
					laytpl(teacherInfo).render(userKey, function(html) {
						$("#teacherInfoView").html(html)
						element.render()						
					})
				}
				
				}
			
			
		

		
		form.val('person', {
				"name":userKey.name,
				"teacherId":userKey.teacherId,
				
			})
		form.val('password', {
			"teacherId": userKey.teacherId,
		
		})
		
		$.ajax({
			url:"http://localhost:8888/teacher/getTeacherByTeacherId",
			data:{"teacherId":userKey.teacherId},
			success:function(data){
				var data = data.data;
				$("#qq").val(data.qq)
				$("#strength").val(data.strength)
				$("#honour").val(data.honour)
				var arr = $("#freeTime").val().split(",")
				for(var i = 0;i<arr.length;i++){
					if(arr[i] == 1) {
						$("#freeTime[1]").attr("checked","checked")
						form.render('checkbox','password')
					} else if(arr[i] == 2) {
						$("#freeTime[2]").attr("checked","checked")
						form.render('checkbox','password')
					} else if(arr[i] == 3) {
						$("#freeTime[3]").attr("checked","checked")
						form.render('checkbox','password')
					} else if(arr[i] == 4) {
					   $("#freeTime[4]").attr("checked","checked")
					   form.render('checkbox','password')
					} else if(arr[i] == 5) {
						$("#freeTime[5]").attr("checked","checked")
						form.render('checkbox','password')
					} else if(arr[i] == 6) {
						$("#freeTime[6]").attr("checked","checked")
						form.render('checkbox','password')
					} else if(arr[i] == 7) {
						$("#freeTime[7]").attr("checked","checked")
						form.render('checkbox','password')
					}
				}
				
			}
		})
		
		var arr = new Array();
		form.on('checkbox(test1)', function(data) {
			if(data.elem.checked == true) {
				//			console.log(arr.toString())
				arr.push(data.value)
				for(var i = 0; arr.length - 1 > i; i++) {
					for(var j = i + 1; j < arr.length; j++) {
						if(arr[j] == arr[i]) {
							arr.splice(j, 1); //删除之后，数组长度随之减少 
							j--;
						}
					}
				}
				arr.join(",")
			} else {
				//			console.log(data.value +"没有选择")
				for(var i = 0; i < arr.length; i++) {
					if(arr[i] == data.value) {
						arr.splice(i, 1);
					}
				}
			}
		
			for(var i = 0; arr.length - 1 > i; i++) {
				for(var j = i + 1; j < arr.length; j++) {
					if(arr[j] == arr[i]) {
						arr.splice(j, 1); //删除之后，数组长度随之减少 
						j--;
					}
				}
			}
			//		console.log(arr.toString())
			$("#freeTime").val(arr.toString())
		});
		//监听提交
		form.on('submit(submitPerson)', function(data) {
			$.ajax({
				type:"post",
				url:"http://localhost:8888/teacher/edit",
				data:data.field,
				success:function(data){
					layer.open({
						content: '修改成功,请重新登录',
						yes: function(index, layero) {
							sessionStorage.clear();
  							location.href ='../../page/teacher/index.html'					
							//do something
							 layer.close(index); //如果设定了yes回调，需进行手工关闭
						}
					});
				},
				error:function(){
					layer.msg('修改失败', {					
						anim: 6
					});
				}
			});			
			
			return false;
		});
		
		//监听提交
		form.on('submit(submitPersonPassword)', function(data) {
			$.ajax({
				type: "post",
				url: "http://localhost:8888/teacher/modify",
				data: data.field,
				success: function(data) {
					layer.open({
						content: '修改成功,请重新登录',
						yes: function(index, layero) {
							sessionStorage.clear();
							location.href = '../../page/teacher/index.html'
							//do something
							layer.close(index); //如果设定了yes回调，需进行手工关闭
						}
					});
				},
				error: function() {
					layer.msg('修改失败', {
						anim: 6
					});
				}
			});
		
			return false;
		});
  });

